package com.burns.ppms.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 这个类主要是是将conf中的properties文件中的配置信息保存起来，方便使用
 * 
 * @author Administrator
 * 
 */
public class PropertyUtil {
	private static String PROPERTIES_FILE = "files/VPM.properties";
	private static Properties p;
	private static PropertyUtil propertyUtil;
	private static FileInputStream inputStream;

	public PropertyUtil() {
		this.p = new Properties();
	}

	public static PropertyUtil getPropertyUtil() {
		if (propertyUtil == null) {
			propertyUtil = new PropertyUtil();
			p = new Properties();
			try {
				// p.load(new
				// InputStreamReader(Client.class.getClassLoader().getResourceAsStream(GlobalVariableUtil
				// .getCapitalRootPath()+CAPITAL_VPM_602), "UTF-8"));
				inputStream = new FileInputStream(PROPERTIES_FILE);
				BufferedReader bf = new BufferedReader(new InputStreamReader(
						inputStream, "utf-8"));
				p.load(bf);
				System.out.println("配置文件信息:" + p);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return propertyUtil;
	}

	public String getValue(String key) {

		return p.getProperty(key).trim();
	}

	public Map<String, String> getAllInfo() {
		Map<String, String> map = new HashMap<String, String>();
		for (Object key : p.keySet()) {
			map.put(key.toString(), (String) p.get(key));
//			System.out
//					.println(key.toString() + ">>>>>" + p.get(key).toString());
		}

		return map;

	}

	public static void main(String[] args) {
		PropertyUtil u = PropertyUtil.getPropertyUtil();
		Map<String,String> map = u.getAllInfo();
		for (String key : map.keySet()) {
			System.out.println("key>>>"+key+"==============value"+map.get(key));
		}
		
//		循环输出map；

	}
}
